<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2008 XBRL International. All Rights Reserved. -->
<?xml-stylesheet type="text/xsl" href="../stylesheets/conformanceFunction.xsl"?>
<testcase
  xmlns="http://xbrl.org/2008/conformance"
  xmlns:reg="http://xbrl.org/2008/registry"
  xmlns:fcn="http://xbrl.org/2008/function"
  xmlns:cfcn="http://xbrl.org/2008/conformance/function"
  xmlns:xbrli="http://www.xbrl.org/2003/instance"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xfi="http://www.xbrl.org/2008/function/instance"
  xmlns:xfie="http://www.xbrl.org/2008/function/instance/error"
  xmlns:xqt-err="http://www.w3.org/2005/xqt-errors"
  xmlns:concept="http://xbrl.org/formula/conformance/example" 
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xsi:schemaLocation="
  http://xbrl.org/2008/registry ../schemas/registry.xsd
  http://xbrl.org/2008/function ../schemas/function.xsd
  http://xbrl.org/2008/conformance ../schemas/conformance.xsd
  http://xbrl.org/2008/conformance/function ../schemas/conformanceFunction.xsd
  ">
  <owners>
    <reg:owner id="herm">
      <reg:name>Herm Fischer</reg:name>
      <reg:affiliation>UBMatrix / Mark V Systems</reg:affiliation>
      <reg:email>fischer@markv.com</reg:email>
     <reg:assumedOwnership moment="2008-02-19T00:00:00" />
    </reg:owner>
  </owners>

  <number>80127</number>

  <name>Function test xfi:period-end</name>

  <documentation>
    <xhtml:p>
      Tests of function xfi:period-end($period as element(xbrli:period)) as xs:dateTime
      </xhtml:p>
  </documentation>

  <reference xlink:type="simple" xlink:href="http://www.xbrl.org/Specification/XF-PWD-2006-12-07.htm#_Toc152670682"/>

  <reference xlink:type="simple" xlink:href="http://www.xbrl.org/Specification/XF-PWD-2006-12-07.htm"/>

  <variation id="V-01">
    <name>xfi:period-end returns correct dateTime for an instant context with date only</name>

    <documentation>
      <xhtml:p>
        Tests that either a the instant dateTime element is provided, or an equivalent atomic value of expected dateTime (note that date-only is incremented by one day to represent last instant in date, but date-time does not have its day incremented, per v-04 test below).
      </xhtml:p>
    </documentation>

    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V01" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V01">
         xfi:period-end( /xbrli:xbrl/xbrli:context[@id eq 'context-earth']/xbrli:period )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         ($result instance of element(*,xs:dateTime) or $result instance of xs:dateTime) and 
         count( $result ) eq 1 and 
         $result eq xs:dateTime("2008-01-01T00:00:00") 
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-02">
    <name>Returns correct dateTime for concept whose context is instant date (only)</name>
    <documentation>
      <xhtml:p>
        Tests that either a the instant dateTime element is provided, or an equivalent atomic value of expected dateTime.
      </xhtml:p>
    </documentation>

    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V02" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V02">
         xfi:period-end( xfi:period( /xbrli:xbrl/concept:cI[1] ) )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         ($result instance of element(*,xs:dateTime) or $result instance of xs:dateTime) and 
         count( $result ) eq 1 and 
         $result eq xs:dateTime("2008-01-01T00:00:00") 
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-03">
    <name>End instant for start-end duration context with date only</name>
    <documentation>
      <xhtml:p>
        Tests that end instant is properly returned for leap year.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V03" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V03">
         xfi:period-end( xfi:period( /xbrli:xbrl/concept:cD[1] ) )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         ($result instance of element(*,xs:dateTime) or $result instance of xs:dateTime) and 
         count( $result ) eq 1 and 
         $result eq xs:dateTime("2008-02-29T00:00:00") 
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-04">
    <name>End instant for start-end duration context with time not midnight</name>
    <documentation>
      <xhtml:p>
        Tests that end instant is properly returned for date with time, and not advanced to next day.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V04" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V04">
         xfi:period-end( xfi:period( /xbrli:xbrl/concept:cD[3] ) )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         ($result instance of element(*,xs:dateTime) or $result instance of xs:dateTime) and 
         count( $result ) eq 1 and 
         $result eq xs:dateTime("2008-02-28T23:59:59") 
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-04a">
    <name>End instant for start-end duration context with time at preceeding midnight</name>
    <documentation>
      <xhtml:p>
        Tests that end instant is properly returned for date with time, and not advanced to next day.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V04a" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V04a">
         xfi:period-end( xfi:period( /xbrli:xbrl/concept:cD[4] ) )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         ($result instance of element(*,xs:dateTime) or $result instance of xs:dateTime) and 
         count( $result ) eq 1 and 
         $result eq xs:dateTime("2008-02-28T00:00:00") 
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-04b">
    <name>End instant for start-end duration context with time at following midnight</name>
    <documentation>
      <xhtml:p>
        Tests that end instant is properly returned for date with time.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V04b" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V04b">
         xfi:period-end( xfi:period( /xbrli:xbrl/concept:cD[5] ) )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         ($result instance of element(*,xs:dateTime) or $result instance of xs:dateTime) and 
         count( $result ) eq 1 and 
         $result eq xs:dateTime("2008-02-28T24:00:00")
         (: note this dateTime may be parsed same as 2008-02-29T00:00:00 
            and both instants are eq xs:dateTime's anyway :) 
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-05"> 
    <name>Error for forever context</name>
    <documentation>
      <xhtml:p>
        Tests that indicated error is raised for inapplicable context.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V05" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V05">
         xfi:period-end( xfi:period( /xbrli:xbrl/concept:cD[2] ) )
      </cfcn:call>
    </inputs>
    <outputs> 
      <error>xfie:PeriodIsForever</error>
    </outputs>
  </variation>

  <variation id="V-06">
    <name>Wrong node to function</name>
    <documentation>
      <xhtml:p>
        XPath-defined error for node type incorrect.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V06" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V06">
         xfi:period-end( /xbrli:xbrl/concept:cD[2] )
      </cfcn:call>
    </inputs>
    <outputs>
      <error>xqt-err:XPTY0004</error>
    </outputs>
  </variation>  

  <variation id="V-07">
    <name>A sequence of periods as argument</name>
    <documentation>
      <xhtml:p>
        XPath-defined error for node type incorrect arity of argument.
      </xhtml:p>
    </documentation>
    <inputs>
      <schema xlink:type="simple" xlink:href="period-end-tests.xsd"/>
      <instance readMeFirst="true" id="V07" xlink:type="simple" xlink:href="hello-worlds-instance.xml"/>
      <cfcn:call file="V07">
         xfi:period-end( /xbrli:xbrl/xbrli:context[@id ne 'planet-earth']/xbrli:period )
      </cfcn:call>
    </inputs>
    <outputs>
      <error>xqt-err:XPTY0004</error>
    </outputs>
  </variation>

  <revisions>
    <reg:revision on="2008-02-19T00:00:00" by="herm">
      <xhtml:p>
        Created the test case.
      </xhtml:p>
    </reg:revision>
    <reg:revision on="2008-04-14T00:00:00" by="herm">
      <xhtml:p>
        Added more date-with-time variations.
      </xhtml:p>
    </reg:revision>
  </revisions>

</testcase>



